import { FETCH_DETAIL, POST_VOTE, POST_COMMENT, POST_SURVEY, INIT_ARTICLE_DATA } from '../actions/detail';

const INITIAL_STATE = { article: null, vote: null, comments: [], survey: null, surveyResult: null };

export default function (state = INITIAL_STATE, action) {
    switch (action.type) {
        case FETCH_DETAIL:
            return {
                article: action.payload.data.article,
                vote: action.payload.data.vote,
                comments: action.payload.data.comments,
                survey: action.payload.data.survey,
                surveyResult: action.payload.data.surveyResult,
                loginUrl: action.payload.data.loginUrl
            };
        case POST_VOTE:
            return {
                ...state,
                vote: action.payload.data
            }
        case POST_COMMENT:
            return {
                ...state,
                comments: action.payload.data
            }
        case POST_SURVEY:
            return {
                ...state,
                survey: action.payload.data.survey,
                surveyResult: action.payload.data.surveyResult
            }
        
        case INIT_ARTICLE_DATA:
            return { ...state, article: undefined } ;
        default:
            return state;
    }
}

